package edu.gatech.aristotle.random.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;



import net.util.Debug;
import net.util.File_Handler;
import edu.gatech.aristotle.random.experiment.MultipleBugExperiment;
import edu.gatech.aristotle.random.experiment.RandomnessExperiment;
import edu.gatech.aristotle.random.experiment.SpaceRandomTestCaseAnalyzer;
import edu.gatech.aristotle.random.ineqalities.ChernoffBound;
import edu.gatech.aristotle.random.inputGenerator.Print_Token_RandomInputGenerator;
import edu.gatech.aristotle.random.inputGenerator.Schedule_RandomInputGenerator;
import edu.gatech.aristotle.random.inputGenerator.TCAS_RandomInputGenerator;
import edu.gatech.aristotle.random.util.CONSTANT_FILE_NAME;
import edu.gatech.aristotle.random.util.RandomnessSelector;
import edu.gatech.aristotle.random.util.Util_Math;

/**
 * 
 * @author paul
 *
 * java -Xms1400M -Xmx1400M
 */
public class MainTester {
	
	static public void main( String[] args ) {		
		//testMultipleBugExperiment();
		
		//testSpaceRandomTestCaseAnalyzer();		
		//test_schedule_InputGenerator();		
		//test_tcas_InputGenerator();		
		//test_print_token_InputGenerator();		
		//testExperiment();
		//testBatchChernoffBound();
		testChernoffBound();
		//testRandomnessHandler();

		//testSubjectReport();
		
		System.out.println( "Test done.");
		
	}
	

	private static void testMultipleBugExperiment(){
		MultipleBugExperiment multipleBugExperiment	= new MultipleBugExperiment();
		String fileName	= "070826_0103.txt";
		ArrayList<Integer> testResult	= multipleBugExperiment.readInTestResult(
												CONSTANT_FILE_NAME.print_token_multiple_bugs_result_dir + fileName);
		Debug.printCollection( testResult );
//		
//		ArrayList<Integer> allFailedIndice	= multipleBugExperiment.findAllFailedIndice
//										( CONSTANT_FILE_NAME.print_token_multiple_bugs_result_dir + fileName );
//		Debug.printCollection( allFailedIndice );
//		
//		ArrayList<Integer> threeBugsFailedIndice	= multipleBugExperiment.findNVersionFailedIndice( 2, 
//																CONSTANT_FILE_NAME.print_token_multiple_bugs_result_dir + fileName );
//		Debug.printCollection( threeBugsFailedIndice );
//		Debug.println( threeBugsFailedIndice.size() );
	}
	
	
	private static void testSpaceRandomTestCaseAnalyzer() {		
		int[] versions = {1, 9, 13, 17, 24, 28, 34};
		
		for ( int k = 0; k < versions.length; k++ ){
			
			for ( int n = 1; n < 11; n++ ){
				int failedTestCase	= new SpaceRandomTestCaseAnalyzer().
												findKthVersionNthThousandTestCaseReport( versions[k], n );	
				System.out.println( "version, " +  versions[k] + ", n-th k, " + n + ", failedTestCase, " + failedTestCase );
			}
		}
		
	}

	static private void test_schedule_InputGenerator(){
		System.out.println( "test_tcas_InputGenerator() " );
		Debug.println( "\n=====\n");
		String randomInput;
		try {
			randomInput = new Schedule_RandomInputGenerator().doBatchInput();
			
			Debug.println( randomInput );	
		} catch (IOException e) {
			e.printStackTrace();
		}
			
	}
	
	static private void test_tcas_InputGenerator(){
		System.out.println( "test_tcas_InputGenerator() " );
		Debug.println( "\n=====\n");
		String tcasRandomInput;
		try {
			tcasRandomInput = new TCAS_RandomInputGenerator().doBatchInput();
			
			Debug.println( tcasRandomInput );	
		} catch (IOException e) {
			e.printStackTrace();
		}
			
	}
	
	static private void test_print_token_InputGenerator(){		
			Debug.println( "\n=====\n");
			String randomInputToPrintTokens	= new Print_Token_RandomInputGenerator().doBatchMultiLine_print_tokenInput();
																	//doBatchDefaultLengthScope_print_tokensInput();
			
			Debug.println( randomInputToPrintTokens );		
	}
	
	static private void testSubjectReport(){
		new RandomnessExperiment().makeSubjectReport();
	}
	
	
	static private void testChernoffBoundExperiment() {
		RandomnessExperiment randomnessExperiment	= new RandomnessExperiment();
		try {
			//randomnessExperiment.doChernoffMixedProgramExperiment();
			//randomnessExperiment.doChernoffBatchProgramExperiment();
			//randomnessExperiment.doChernoffBatchVersionExperiment(CONSTANT_FILE_NAME.matrixNewFormatFileNames[7]);
			for ( int i = 0; i < CONSTANT_FILE_NAME.matrixNewFormatFileNames.length; i++ )
				randomnessExperiment.doBatchVersionRandomSampleDeviationExperiment( CONSTANT_FILE_NAME.matrixNewFormatFileNames[i] );
		} catch (IOException e) {
			e.printStackTrace();
		}		
		
		//randomnessExperiment.doChernoffExperiment( CONSTANT_FILE_NAME.matrixNewFormatFileNames[7], 28, 28 );
		//randomnessExperiment.doSingleChernoffExperiment( CONSTANT_FILE_NAME.matrixNewFormatFileNames[7], 28 );
	}
	
	static private void testChernoffBound(){
		int 	sample		= 2000;
		int 	passed		= 1900;
		double	deviation	= 0.05;
		
		ChernoffBound	chernoffBound	= new ChernoffBound( deviation, passed, sample );
		Debug.println();
	
		System.out.println( chernoffBound.makeReport() );
	}
	
	static private void testBatchChernoffBound(){		
		String report	= new ChernoffBound().makeBatchReport();		
		
		try {
			File_Handler.write_to_file( CONSTANT_FILE_NAME.outputDir + "batchChernoffReport.txt", report );
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	static private void testRandomnessHandler(){
		int[] radomIndices	= new RandomnessSelector().selectRandomIndex( 1000, 100 );
		
		for ( int i = 0; i < radomIndices.length; i++ ){
			Debug.println( radomIndices[i] );
			
			for (int j = 0; j < radomIndices.length; j++ ){
				if ( radomIndices[i] == radomIndices[j] ){
					Debug.println( "\trandom index equal: " + i + " at " + j );
				}
			}
		}		
	}
	
	private static void rateTester(){
		int total = 2649;
		int failed = 23;
		
		Debug.println( Util_Math.rate( total - failed , total ) );
	}
}
